package com.controllers;

import java.io.IOException;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.cglib.proxy.Dispatcher;

import org.primefaces.context.RequestContext;
import org.springframework.web.filter.GenericFilterBean;
import org.springframework.web.servlet.DispatcherServlet;

public class ExpiredSessionFilter extends GenericFilterBean {

	static final String FILTER_APPLIED = "__spring_security_expired_session_filter_applied";

	@Override
	public void doFilter(ServletRequest req, ServletResponse res,
			FilterChain chain) throws IOException, ServletException {

	        HttpServletRequest request = (HttpServletRequest) req;
	        HttpServletResponse response = (HttpServletResponse) res;

	        if (request.getRequestURL().indexOf("j_spring_security_check") != -1 || request.getAttribute(FILTER_APPLIED) != null) {
	            chain.doFilter(request, response);
	            return;
	        }

	        request.setAttribute(FILTER_APPLIED, Boolean.TRUE);
	        if (request.getRequestedSessionId() != null && !request.isRequestedSessionIdValid()) {               
	        	try {
					throw new Exception("sss");
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	        }

	        chain.doFilter(request, response);
	    }
}